/*
 * File Name:               UIGameviewEditor.cs
 *
 * Description:             普通类
 * Author:                  lisiyu
 * Create Date:             2016/08/05
 */

using UnityEditor;

public class UIGameviewEditor
{
    /// <summary>
    /// 设置GameView视窗分辨率 
    /// </summary>
    public static void setSize(string name, int width, int height)
    {
        System.Type gameViewType = System.Type.GetType("UnityEditor.GameView,UnityEditor");
        var win = EditorWindow.GetWindow(gameViewType);
        var currentGameViewSizeType = gameViewType.GetProperty("currentGameViewSize", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
        var currentGameViewSize = currentGameViewSizeType.GetValue(win, null);
        var gameViewSizeType = currentGameViewSize.GetType();
        gameViewSizeType.GetProperty("width").SetValue(currentGameViewSize, width, null);
        gameViewSizeType.GetProperty("height").SetValue(currentGameViewSize, height, null);
        gameViewSizeType.GetProperty("sizeType").SetValue(currentGameViewSize, 0, null);
        gameViewSizeType.GetProperty("baseText").SetValue(currentGameViewSize, name, null);
        win.Repaint();
        // gameViewType.GetMethod("GameViewAspectWasChanged", System.Reflection.BindingFlags.Instance
        // | System.Reflection.BindingFlags.NonPublic).Invoke(win, null);
    }
}